/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/12 10:36
  *
  * @file       pd_timer.h
  * @brief      Header file of Timer peripheral driver.
  *
  * @note       This file contains the Timer object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/6/12     Chris        the first version
  *
  ******************************************************************************
  */

#ifndef JLC_SKY_TIMER_H
#define JLC_SKY_TIMER_H

#include <stm32f407xx.h>

struct TimerVtbl;

/** @defgroup Object properties
  * @{
  */
typedef struct {
    TIM_TypeDef *TIMx;

    uint16_t Prescaler;
    uint32_t Autoreload;
    uint32_t CounterMode;
    uint32_t ClockDivision;
    uint32_t RepetitionCounter;

    // Timer virtual table
    struct TimerVtbl *vptr;
} Timer;
/**
 * @}
 */

/** @defgroup Object virtual table definition
  * @{
  */
struct TimerVtbl {
    void (*init)(const Timer *this);

    uint32_t (*get_counter)(const Timer *this);
};
/**
 * @}
 */

/** @defgroup Object constructor and member function declaration
  * @{
  */
void Timer_constructor(Timer *this, TIM_TypeDef *TIMx, uint16_t Prescaler, uint32_t Autoreload);
/**
 * @}
 */

/** @defgroup Object virtual table function implementation
  * @{
  */
static inline void Timer_init(const Timer *this) {
    this->vptr->init(this);
}

static inline uint32_t Timer_getCounter(const Timer *this) {
    return this->vptr->get_counter(this);
}
/**
 * @}
 */


#endif //JLC_SKY_TIMER_H
